-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(storageincentives): storage incentives phase 4 #4345
Conversation
Co-authored-by: Viktor Levente Tóth <[email protected]>
pkg/storageincentives/agent.go
Outdated
sample, err := a.makeSample(ctx, storageRadius) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
a.logger.Info("produced sample", "hash", sample.ReserveSampleHash, "radius", sample.StorageRadius, "round", round) | ||
|
||
a.state.SetSampleData(round, sample, time.Since(now)) | ||
a.state.SetSampleData(round, sample) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was the duration of the sampler removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The makeSample
function saves the duration into a.metrics.SampleDuration
and on rchash endpoint call, SampleWithProofs
calculates the process time. This additional time handling seemed redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the API returns the duration though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the current version also returns (storageincentives/agent.go:596)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the redistributionstate endpoints needs it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I see
pkg/api/rchash.go
Outdated
@@ -19,8 +19,9 @@ func (s *Service) rchash(w http.ResponseWriter, r *http.Request) { | |||
logger := s.logger.WithName("get_rchash").Build() | |||
|
|||
paths := struct { | |||
Depth *uint8 `map:"depth" validate:"required"` | |||
Depth uint8 `map:"depth" validate:"min=0"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The min=0
tag is not needed, the 0 is the minimum of an unsigned integer.
pkg/api/rchash.go
Outdated
@@ -34,7 +35,14 @@ func (s *Service) rchash(w http.ResponseWriter, r *http.Request) { | |||
return | |||
} | |||
|
|||
resp, err := s.redistributionAgent.SampleWithProofs(r.Context(), anchor1, *paths.Depth) | |||
anchor2, err := hex.DecodeString(paths.Anchor2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to rather register a new pre-map hook (api.go:281):
"decHex": func(v string) (string, error) {
buf, err := hex.DecodeString(v)
return string(buf), err
},
Then simply use map:"anchor2,decHex"
above and caste []bytes(anchor1)
when you want to use it. The same goes for the Anchor1
.
pkg/bmt/bmt.go
Outdated
@@ -40,6 +40,19 @@ type Hasher struct { | |||
span []byte // The span of the data subsumed under the chunk | |||
} | |||
|
|||
// facade |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment should describe what this function does and should start with the: NewHasher... (by Golang convention).
pkg/bmt/proof.go
Outdated
for i := p.size; i < p.maxSize; i += len(zerosection) { | ||
_, err := p.Write(zerosection) | ||
if err != nil { | ||
return []byte{}, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return nil, err
.
return []byte{}, err | ||
} | ||
} | ||
return p.Hasher.Hash(b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stay consistent, return p.Hash(b)
will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it calls its ancestor's hash function that contains the logic for the hash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stay consistent,
return p.Hash(b)
will do.
i dont think so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're doing the same with p.Write
instead of p.Hasher.Write
above, which is also Hasher
's method. So I'd recommend being consistent.
ChunkAddr string `json:"chunkAddr"` | ||
} | ||
|
||
// Transforms arguments to ChunkInclusionProof object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functin description should start with its name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not fixed.
} | ||
|
||
// Transforms arguments to ChunkInclusionProof object | ||
func NewChunkInclusionProof(proofp1, proofp2 bmt.Proof, proofp3 bmt.Proof, sampleItem storer.SampleItem) (ChunkInclusionProof, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This proofp1, proofp2 bmt.Proof, proofp3 bmt.Proof
can be rewriten as proofp1, proofp2, proofp3 bmt.Proof
.
} | ||
|
||
// Transforms proof object to its hexadecimal representation | ||
func newHexProofs(proof bmt.Proof) hexProof { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function description should start with its name.
|
||
// to generate uploads using the input | ||
// cat socs.txt | tail 19 | head 16 | perl -pne 's/([a-f0-9]+)\t([a-f0-9]+)\t([a-f0-9]+)\t([a-f0-9]+)/echo -n $4 | xxd -r -p | curl -X POST \"http:\/\/localhost:1633\/soc\/$1\/$2?sig=$3\" -H \"accept: application\/json, text\/plain, \/\" -H \"content-type: application\/octet-stream\" -H \"swarm-postage-batch-id: 14b26beca257e763609143c6b04c2c487f01a051798c535c2f542ce75a97c05f\" --data-binary \@-/' | ||
func TestSocMine(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description is vague, so I'm not quite sure why this is necessary. If it exists solely to generate input for the soc
endpoint test, then consider generating fixtures and writing a soc test using them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this was meant to utilize the test's output and upload chunks trough the SOC API endpoint.
the test was running in a different environment where this test couldn't be called (no build tools installed etc.)
the comment was made by @zelig . shall we remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from some comments, LGTM!
return []byte{}, err | ||
} | ||
} | ||
return p.Hasher.Hash(b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're doing the same with p.Write
instead of p.Hasher.Write
above, which is also Hasher
's method. So I'd recommend being consistent.
pkg/storageincentives/agent.go
Outdated
} | ||
|
||
// Only called by rchash API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method description should start with its name.
ChunkAddr string `json:"chunkAddr"` | ||
} | ||
|
||
// Transforms arguments to ChunkInclusionProof object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not fixed.
Co-authored-by: Viktor Levente Tóth <[email protected]> Co-authored-by: nugaon <[email protected]> Co-authored-by: istae <[email protected]>
Co-authored-by: Viktor Levente Tóth <[email protected]> Co-authored-by: nugaon <[email protected]> Co-authored-by: istae <[email protected]>
feat(bmt): bmt related changes as a basis for storage incentive phase 4 #4343feat(storageincentives): test and utility to generate SOCs by mining ids for storage incentives phase 4 testing #4344feat(ph4): agent and api #4323fix: bump storage-incentives abi to v0.6.0-rc3 #4348